﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using YDWin.Base;
using YDServices;
using YDModel;
using DevExpress.Utils;
using YDCommon;

namespace YDWin.SystemParameter
{
    public partial class AddSystemParameterForm : AddForm
    { 
        SystemParameterService svr = new SystemParameterService();
        public T_System_Parameter editTu = new T_System_Parameter();
        public string typeCode = ""; 
        public string state = "";
        public AddSystemParameterForm()
        {
            InitializeComponent();
 
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
          
            T_System_Parameter fact = new T_System_Parameter();
            if (!state.Equals("") && state.Equals("Edit"))
            {
                fact = editTu;
            }

            if (txtParameterName.Text.Trim().Equals(""))
            {
                Utils.ShowPrompt(MessageType.mtWarning, "参数名称不能为空!\n"); 
                return;
            }

            fact.Parameter_Name = txtParameterName.Text;
            WaitDialogForm sdf = new WaitDialogForm("", "正在保存......");
            if (!state.Equals("") && state.Equals("Edit"))
            {
                svr.EditItem(fact);
            }
            else
            {
                fact.Type_Code = typeCode;
                svr.AddItem(fact);
            }
      

            sdf.Close();

            if (svr.HasError)
            {
                Utils.ShowPrompt(MessageType.mtError, "规格信息保存失败：" + svr.Errors);
                svr.Errors.Clear();
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();

        }

        private void AddSystemParameterForm_Load(object sender, EventArgs e)
        {
            if (!state.Equals("") && state.Equals("Edit")) 
            {
                txtParameterName.Text = editTu.Parameter_Name; 
            }
        }
 
    }
}